package bTree.LeetCode;

import java.util.Stack;

public class 每日温度 {
    public int[] dailyTemperatures(int[] temperatures) {
        int n=temperatures.length;
        int []res=new int[n];
        Stack<Integer>stack=new Stack<>();
        stack.push(0);
        for (int i = 1; i < n; i++) {
            if(temperatures[i]<=temperatures[stack.peek()]){
                stack.push(i);
            }else{
                while (!stack.isEmpty()&&temperatures[i]>temperatures[stack.peek()]){
                    res[stack.peek()]=i-stack.pop();
                }
                stack.push(i);
            }
        }

        return res;
    }
}
